/***************************************************************************
 *  Filename: logger.cpp
 *  Class: Logger
 *  
 *  Copyright 2012  Jacco van der Spek
 *  <jaccovdspek@gmail.com>
 *
 *  Copyright 2012  Mario Henrique Voorsluys
 *  <forcaeluz@gmail.com>
 *  
 ****************************************************************************/

/*
 *
 * This file is part of %ProjectName%.
 *
 *    %ProjectName% is free software: you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation, either version 3 of the License, or
 *    (at your option) any later version.
 *
 *    %ProjectName% is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License
 *    along with %ProjectName%.  If not, see <http://www.gnu.org/licenses/>.
 */

#include "logger.h"
#include <QDebug>
Logger::Logger(QObject *parent) :
    QObject(parent)
{
    setFileName("steady.csv");
}

void Logger::logData(int time, float troll, float tpitch, float tyaw, float vx, float vy, float vz, qint32 altitude){
    qDebug() << "Logging data to" << fileName;
    QFile outFile(fileName);
    outFile.open(QIODevice::WriteOnly | QIODevice::Append);
    QTextStream ts(&outFile);
    ts << time << "," << troll << "," << roll << ","
                        << tpitch << ","  << pitch << "," << tyaw << "," << yaw << ","
       << vx << "," << vy << "," << vz << "," << gaz << "," << altitude << endl;
    qDebug() << "Data Logged";
}

void Logger::setFileName(QString name){
    qDebug() << "Setting filename";
    fileName=name;
    QFile outFile(fileName);
    outFile.open(QIODevice::WriteOnly | QIODevice::Append);
    QTextStream ts(&outFile);
    ts << "Test Start" << endl;
    ts << "Time(ms)" << "," << "Roll"<< "," << "DesRoll" <<
          "," << "Pitch" << ","  << "DesPitch" << "," << "Yaw" << "," << "DesYaw" << ","
       << "vx" << "," << "vy" << "," << "vz" << "," << "DesVz" << "," << "altitude" << endl;
}

void Logger::setDesires(float troll, float tpitch, float tyaw, float tgaz){
    roll = troll;
    pitch = tpitch;
    yaw = tyaw;
    gaz = tgaz;
}
